package com.ccx.coachsite;

import com.ccx.coachsite.util.SharedPreferencesUtil;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;

public class StartActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 判断应该进入向导页面或者闪屏
		boolean isLatestVersion = true;
		int versionCode = -1;
		try {
			int lastVersionCode = SharedPreferencesUtil.getInt(this,
					"lastVersionCode", -1);

			PackageInfo packageInfo = this.getPackageManager().getPackageInfo(
					this.getPackageName(), 0);
			versionCode = packageInfo.versionCode;
			isLatestVersion = versionCode <= lastVersionCode;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

		if (isLatestVersion) {
			Intent intent = new Intent(this, MainSplash.class);
			startActivity(intent);
			finish();
		} else {
			Intent intent = new Intent(this, GuideActivity.class);
			startActivity(intent);
			finish();

			SharedPreferencesUtil.setInt(this, "lastVersionCode", versionCode);
		}
	}

}
